package com.xbts.web.controller.editor;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.enums.BusinessType;
import com.xbts.system.domain.SeiConfigMaterial;
import com.xbts.system.service.ISeiConfigMaterialService;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 素材配置Controller
 * @author xbts
 * @date 2023-09-07
 */
@Api("素材配置")
@RestController
@RequestMapping("/system/material/config")
public class SeiConfigMaterialController extends BaseController {

    @Autowired
    private ISeiConfigMaterialService seiConfigMaterialService;

    /**
     * 查询素材配置列表
     */
    @ApiOperation("查询素材配置列表")
    @PreAuthorize("@ss.hasPermi('system:material:list')")
    @GetMapping("/list")
    public TableDataInfo list() {
        List<SeiConfigMaterial> list = seiConfigMaterialService.selectSeiConfigMaterialList(new SeiConfigMaterial());
        return getDataTable(list);
    }

    /**
     * 导出素材配置列表
     */
    @ApiOperation("导出素材配置列表")
    @PreAuthorize("@ss.hasPermi('system:material:export')")
    @Log(title = "素材配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody SeiConfigMaterial seiConfigMaterial) {
        List<SeiConfigMaterial> list = seiConfigMaterialService.selectSeiConfigMaterialList(seiConfigMaterial);
        ExcelUtil<SeiConfigMaterial> util = new ExcelUtil<SeiConfigMaterial>(SeiConfigMaterial.class);
        util.exportExcel(response, list, "素材配置数据");
    }

    /**
     * 获取素材配置详细信息
     */
    @ApiOperation("获取素材配置详细信息")
    @ApiImplicitParam(name = "materialId", value = "素材配置ID", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:material:query')")
    @GetMapping(value = "/{materialId}")
    public AjaxResult getInfo(@PathVariable("materialId") String materialId) {
        return success(seiConfigMaterialService.selectSeiConfigMaterialByMaterialId(materialId));
    }

    /**
     * 新增素材配置
     */
    @ApiOperation("新增素材配置")
    @PreAuthorize("@ss.hasPermi('system:material:add')")
    @Log(title = "素材配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SeiConfigMaterial seiConfigMaterial) {
        return toAjax(seiConfigMaterialService.insertSeiConfigMaterial(seiConfigMaterial));
    }

    /**
     * 修改素材配置
     */
    @ApiOperation("修改素材配置")
    @PreAuthorize("@ss.hasPermi('system:material:edit')")
    @Log(title = "素材配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SeiConfigMaterial seiConfigMaterial) {
        return toAjax(seiConfigMaterialService.updateSeiConfigMaterial(seiConfigMaterial));
    }

    /**
     * 删除素材配置
     */
    @ApiOperation("删除素材配置")
    @ApiImplicitParam(name = "materialIds", value = "素材配置ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:material:remove')")
    @Log(title = "素材配置", businessType = BusinessType.DELETE)
	@PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> materialIds) {
        return toAjax(seiConfigMaterialService.deleteSeiConfigMaterialByMaterialIds(materialIds));
    }
}
